package com.ohuang.apkMerge

import java.util.*

fun main(args: Array<String>) {
    if (args.isEmpty()) {
        println("-a  <path1>  <path2>   合并apk反编译环境")
        println("-a1  <path1>  <path2>   合并apk反编译环境(文件重名覆盖)")
        println("-anew  <path1>  <path2>   合并apk反编译环境(新的ID段去重直接复制id)")
        println("-a1new  <path1>  <path2>   合并apk反编译环境(文件重名覆盖、新的id段去重直接复制id)")
        println("-c <path1>  <path2>  复制文件(覆盖重复文件)")
        println("-c1 <path1>  <path2>  复制文件(不覆盖重复文件)")
        println("-v <path1>  <path2>  合并文件夹下的xml")
        println("-vnew <path1>  <path2>  合并文件夹下的xml(新的ID段去重直接复制id)")
        println("-m <path1>  <path2>  合并AndroidManifest")
        println("-s <path1>  <path2> 复制smali_classes并更新R.smali")
        println("-r <public.xml path>  <smali_classes path> 更新R.smali")
        println("-dr   <smali_classes path> 删除R.smali")
        println("-gr   <smali_classes path> <R.txt path> 根据R.smali生成R.txt(用于aar)")
        println("-xml <path1>  xml去重(根据name)")
        println("-outReplaceConfig  <path1>  输出outReplaceConfig.json模板")
        println("-replace  <path1> <path2> <ReplaceConfig.json path>  第三方库包名替换")
    } else {
        var s = args[0]

        when (s) {
            "-a" -> {
                //-a  <path1>  <path2>   合并apk反编译环境
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                mergeApk(path1, path2)
            }
            "-a1" -> {
                //-a  <path1>  <path2>   合并apk反编译环境
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                mergeApk2(path1, path2)
            }
            "-anew" -> {
                //-a  <path1>  <path2>   合并apk反编译环境
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                mergeApk(path1, path2,true)
            }
            "-a1newId" -> {
                //-a  <path1>  <path2>   合并apk反编译环境
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                mergeApk2(path1, path2,true)
            }
            "-c"->{
                //-c <path1>  <path2>  复制文件(覆盖重复文件)
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                copayFileLog(path1,path2, isCover = true)
            }
            "-c1"->{
                //-c1 <path1>  <path2>  复制文件(不覆盖重复文件)
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                copayFileLog(path1,path2, isCover = false)
            }
            "-v"->{
                //-v <path1>  <path2>  合并文件夹下的xml
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                mergeValueXml(path1,path2)
            }
            "-vnew"->{
                //-v <path1>  <path2>  合并文件夹下的xml
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                mergeValueXml(path1,path2,true)
            }
            "-m"->{
                //-m <path1>  <path2>  合并AndroidManifest
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                mergeManifest(path1,path2)
            }
            "-s"->{
                //-s <path1>  <path2> 复制smali_classes并更新R.smali
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                copySmaliAndUpdaterSmali(path1,path2,path2+"/res/values/public.xml")
            }
            "-r"->{
                //-r <public.xml path>  <smali_classes path> 更新R.smali
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                updateRSmali2(path1,path2)
            }
            "-dr"->{
                //-r <public.xml path>  <smali_classes path> 更新R.smali
                var path1 = args[1].replace("\"", "").replace("'","")
                println("path1=$path1")
                deleteRSmali(path1)
            }
            "-gr"->{
                //-r <public.xml path>  <smali_classes path> 更新R.smali
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                generateRTxt(path1,path2)
            }

            "-xml"->{
                var path1 = args[1].replace("\"", "").replace("'","")
                println("path1=$path1")
                valueRemoveIdenticalNoPublic(path1)
            }
            "-outReplaceConfig"->{
                var path1 = args[1].replace("\"", "").replace("'","")
                println("path1=$path1")
                outReplaceConfig(path1)
            }

            "-replace"->{
                var path1 = args[1].replace("\"", "").replace("'","")
                var path2 = args[2].replace("\"", "").replace("'","")
                var path3 = args[3].replace("\"", "").replace("'","")
                println("path1=$path1")
                println("path2=$path2")
                println("path3=$path3")
                copyAndChangeFrameWorkPackageName(path1,path2,path3)
            }
        }

    }



}